package com.example.dynamicdatasourcedemo.service.impl;



import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.dynamicdatasourcedemo.dao.UserDao;
import com.example.dynamicdatasourcedemo.entity.User;
import com.example.dynamicdatasourcedemo.service.UserService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *   
 *  Created with IDEA  
 *  @author:尚旭波  
 *  @Date:2018/8/2  
 *  @Time:10:52    
 *  
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;
    private static final String template = "Hello, %s!";


    @Override
    public void addUser(User user) {
        userDao.addUser(user);

        String user1 = String.format(template, "user");
        log.info("User{}",user1);

    }



    @Override
    public void addUserByMaster(User user) {
        log.info("master");
        userDao.addUserByMaster(user);
    }


    @DS("slave1")
    @Override
    public void addUserBySlave(User user) {
        log.info("slave");
        userDao.addUserBySlave(user);
//       开启事务后进行回滚
//        int i = 2/0;
    }
}
